Developer Documentation

QuickTime 4 API Documentation

Programming With QuickTime VR

| Previous | Chapter Contents | Chapter Top | Next |

Manipulating Viewing Angles and Zooming

Perhaps the simplest use of the QuickTime VR Manager is to manipulate the current viewing characteristics of an object or panoramic node. You can use the QTVRGetPanAngle and QTVRSetPanAngle functions to manipulate the pan angle, and you can use the QTVRGetTiltAngle and QTVRSetTiltAngle functions to manipulate the tilt angle. Listing 2-3 illustrates how to pan or tilt a specific number of degrees in a specific direction.

Listing 3 Changing the viewing angle

#define kDirLeft    0L
#define kDirRight   1L
#define kDirUp      2L
#define kDirDown    3L

Boolean MyGoDirByDegrees (QTVRInstance theInstance, long theDir, float theAmt)
{
    float       theAngle;
    Boolean     theMoved = false;   //Did calling this routine result in a movement?

    switch (theDir) {
        case kDirUp:
            theAngle = QTVRGetTiltAngle(theInstance);
            QTVRSetTiltAngle(theInstance, theAngle + theAmt);
            break;
        case kDirDown:
            theAngle = QTVRGetTiltAngle(theInstance);
            QTVRSetTiltAngle(theInstance, theAngle - theAmt);
            break;
        case kDirLeft:
            theAngle = QTVRGetPanAngle(theInstance);
            QTVRSetPanAngle(theInstance, theAngle + theAmt);
            break;
        case kDirRight:
            theAngle = QTVRGetPanAngle(theInstance);
            QTVRSetPanAngle(theInstance, theAngle - theAmt);
            break;
        default:
            break;
    }

    //Now update the image on the screen.
    QTVRUpdate(theInstance, kQTVRStatic);
    
    //Determine whether a movement actually occurred.
    switch (theDir) {
        case kDirUp:
        case kDirDown:
            theMoved = (theAngle != QTVRGetTiltAngle(theInstance));
            break;
        case kDirLeft:
        case kDirRight:
            theMoved = (theAngle != QTVRGetPanAngle(theInstance));
            break;
        default:
            break;
    }
    
    return(theMoved);
}

MyGoDirByDegrees is relatively simple. It first determines the direction in which to move, gets the current pan or tilt angle, and then sets a new pan or tilt angle by adding or subtracting the desired displacement to that angle. Notice that MyGoDirByDegrees calls the QTVRUpdate function to update the image on the screen. This update is necessary whenever you change a viewing characteristic programmatically.

Once the new viewing angle has been set and the new image has been displayed, the MyGoDirByDegrees function determines whether the new pan or tilt angle differs from the pan or tilt angle on entry and passes back a Boolean value to indicate whether the call to MyGoDirByDegrees changed the pan or tilt angle. (The new angle may not be different because, for example, the value was already at some limit or constraint. This information might be useful for determining whether to enable or disable some visual effect in the scene.)

Zooming in or out is just as simple as panning or tilting. For both objects and panoramas, you zoom in or out by changing the field of view of the node. Listing 2-4 defines a function that zooms in or out by a predetermined amount.

Listing 4 Changing the field of view

#define kDirIn      4L
#define kDirOut     5L

void MyZoomInOrOut (QTVRInstance theInstance, long theDir)
{
    float   theFloat;
    
    theFloat = QTVRGetFieldOfView(theInstance);
    switch (theDir) {
        case kDirIn:
            theFloat = theFloat / 2.0;
            break;
        case kDirOut:
            theFloat = theFloat * 2.0;
            break;
        default:
            break;
    }
    QTVRSetFieldOfView(theInstance, theFloat);
    QTVRUpdate(theInstance, kQTVRStatic);
}

The MyZoomInOrOut function defined in Listing 2-4 simply doubles or halves the current field of view, depending on whether you're zooming out or in.


© 1998 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |